package com.cxyzy.basic_libs.view

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import java.util.*

class CircleView(context: Context, attributeSet: AttributeSet? = null) :
    View(context, attributeSet) {
    private var mPaint: Paint = Paint()

    init {
        mPaint.color = Color.parseColor("#fab27b")
        mPaint.isAntiAlias = true
        mPaint.style = Paint.Style.STROKE
        mPaint.strokeWidth = 10f
        start()
    }

    private var mTimer: Timer? = null

    private fun start() {
        mTimer = Timer()
        mTimer?.schedule(object : TimerTask() {
            override fun run() {
                //工作线程中用postInvalidate(); UI线程用invalidate()
                postInvalidate()
            }
        }, 50, 50)

    }

    override fun onDraw(canvas: Canvas) {
        drawCircle(canvas)
    }

    private var padding = 0
    private fun drawCircle(canvas: Canvas) {
        canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), 10f + padding, mPaint)
        padding += 10
    }
}